import { Request, Response } from 'express'
import { rankingService } from '../services/ranking'

export const getGiftRanking = async (req: Request, res: Response) => {
  try {
    const { roomId } = req.params
    const { limit } = req.query
    const ranking = await rankingService.getGiftRanking(roomId, Number(limit))
    res.json(ranking)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getPopularityRanking = async (req: Request, res: Response) => {
  try {
    const { limit } = req.query
    const ranking = await rankingService.getPopularityRanking(Number(limit))
    res.json(ranking)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getRankingHistory = async (req: Request, res: Response) => {
  try {
    const { type, period, roomId } = req.params
    const { page, limit } = req.query

    const history = await rankingService.getRankingHistory(
      type as 'gift' | 'popularity',
      period as 'daily' | 'weekly' | 'monthly',
      roomId,
      Number(page),
      Number(limit)
    )

    res.json(history)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}
